package com.crm.web.controller.clue;


import com.crm.common.core.controller.BaseController;
import com.crm.common.core.domain.AjaxResult;
import com.crm.common.core.page.TableDataInfo;
import com.crm.common.utils.DateUtils;
import com.crm.domain.Activity;
import com.crm.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 活动管理controller
 */
@RestController
@RequestMapping("/clues/activity")
public class ActivityController extends BaseController {
    @Autowired
    private ActivityService activityService;

    /**
     * 查询活动管理列表
     */
    @RequestMapping("/list")
    public TableDataInfo list(Activity activity) {
        startPage();
        List<Activity> list = activityService.selectActivityList(activity);
        Map<String, Object> countParms = activityService.getCountByStatus();
        return getDataTable(list,countParms);
    }

    /**
     * 获取渠道来源
     */
    @GetMapping("/listselect/{channel}")
    public AjaxResult list(@PathVariable("channel") String channel) {
        Activity activity = new Activity();
        Date nowDate = DateUtils.getNowDate();
        HashMap<String, Object> localTime = new HashMap<>();
        localTime.put("localTime", nowDate);
        activity.setParams(localTime);
        activity.setChannel(channel);
        activity.setStatus("2");
        return AjaxResult.success(activityService.selectActivityList(activity));
    }
    /**
     * 根据活动id查询活动信息
     */

    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(activityService.getActivityById(id));
    }
    /**
     * 新增活动管理
     */
    @PostMapping
    public AjaxResult add(@RequestBody Activity activity) {
        return toAjax(activityService.insertActivity(activity));
    }
    /**
     * 修改活动管理
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Activity activity) {
        return toAjax(activityService.updateActivity(activity));
    }
    /**
     * 删除活动管理
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(activityService.deleteActivityByIds(ids));
    }
}